home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 43.zip / Sources C- WorkDisk V.adf / ex / checkdisk2.c < prev    next >
C/C++ Source or Header  |  1987-02-16  |  2KB  |  83 lines

  1. /* checkdisk.c */
  2.  
  3. #include "devices/trackdisk.h"
  4.  
  5. #define BLOCKSIZE TD_SECTOR
  6. #define MEMF_CHIP (1L<<1)
  7.  
  8. unsigned char *diskbuffer;
  9. long td_open_error = -1;
  10.  
  11. struct MsgPort *diskport;
  12. struct IOExtTD *diskreq;
  13.  
  14. extern struct MsgPort *CreatePort();
  15. extern struct IORequest *CreateExtIO();
  16.  
  17. void MotorOnOff(onoff)    /* TURN DISK MOTOR ON/OFF */
  18. long onoff;
  19. {
  20.  diskreq->iotd_Req.io_Length = onoff;
  21.  diskreq->iotd_Req.io_Command = TD_MOTOR;
  22.  DoIO(diskreq);
  23. }
  24.  
  25.  
  26. main(argc,argv)
  27. int argc;
  28. char *argv[];
  29. {
  30. long unit, offset;
  31.  
  32. if (argc>1)
  33. {
  34.  unit = atoi(argv[1]);
  35.  if( unit < 0 || unit > 3) exit(0);
  36. }
  37. else
  38.  unit = 1;
  39.  
  40. if((diskbuffer = AllocMem(BLOCKSIZE,MEMF_CHIP))==0) cleanup();
  41.     
  42. if((diskport = CreatePort(0,0)) == 0) cleanup();
  43. /* make an io request block for communicating with the disk */
  44. if((diskreq = (struct IOExtTD *)CreateExtIO(diskport, sizeof(struct IOExtTD)))== 0)
  45.     cleanup();    
  46.  
  47. if(td_open_error = OpenDevice(TD_NAME,unit,diskreq,0)) cleanup();
  48.  
  49.  
  50. MotorOnOff(1); /* Motor On */
  51.  
  52. for(offset=0;offset<NUMSECS*NUMCYLS*NUMHEADS*BLOCKSIZE;offset+=BLOCKSIZE)    
  53. {
  54.    diskreq->iotd_Req.io_Flags = 0;      
  55.    diskreq->iotd_Req.io_Length = BLOCKSIZE;      
  56.    diskreq->iotd_Req.io_Data = (APTR)diskbuffer;    
  57.    diskreq->iotd_Req.io_Offset = offset; /* type long */
  58.    diskreq->iotd_Req.io_Command = ETD_READ;
  59.         /* check that disk not changed before reading */
  60.    diskreq->iotd_Count = 0xFFFFFFFF;
  61.    diskreq->iotd_SecLabel = 0;        
  62.     
  63.    DoIO(diskreq);
  64.  
  65.    if(diskreq->iotd_Req.io_Error != 0) 
  66.    printf("\nError nr. Error=%ld at Cyl=%ld.",
  67.     diskreq->iotd_Req.io_Error,offset/(NUMSECS*NUMHEADS*BLOCKSIZE));
  68. }
  69. MotorOnOff(0);
  70.  
  71. cleanup();
  72. }    /* end of main */
  73.  
  74. cleanup()
  75. {
  76. if(diskbuffer) FreeMem(diskbuffer,BLOCKSIZE);
  77. if(!td_open_error) CloseDevice(diskreq);
  78. if(diskreq) DeleteExtIO(diskreq, sizeof(struct IOExtTD));
  79. if(diskport) DeletePort(diskport);
  80. exit(0);
  81. }
  82.  
  83.